package algorithm;

import java.util.Random;

/**
 * @author gabriella
 *
 */
public class Rule2Cube extends Rule1Cube {
	
	private int d;
	/**
	 * @param d initial number of defector individuals
	 */
	public Rule2Cube(int n, int S, int R, int T,int P, boolean periodic, int d) {
		super(n, S, R, T, P, periodic);
		this.d = d;
	}
	
	/**
	 * @see algorithm.Algorithm#init(byte[], int[])
	 */
	@Override
	public byte[] init() {
		byte L[] = new byte[nvert];

		Random generator = new Random();

		int def = d;

		if (def < nvert / 2) {
			C = nvert;
			for (int i = 0; i < nvert; i++) {

				L[i] = 1;
			}
			for (int i = 0; i < def; i++) {

				int rand = generator.nextInt(nvert);

				while (L[rand] != 1) {

					rand = generator.nextInt(nvert);
				}
				L[rand] = 0;
				C--;
			}
		} else {
			C = 0;
			for (int i = 0; i < nvert; i++) {

				L[i] = 0;
			}
			for (int i = 0; i < (nvert-def); i++) {

				int rand = generator.nextInt(nvert);

				while (L[rand] != 0) {

					rand = generator.nextInt(nvert);
				}
				L[rand] = 1;
				C++;
			}
		}
		return L;
	}

}
